#!/bin/bash
source openrc.sh
source  /etc/admin-openrc
# database
mysql -uroot -p$DB_PASS -e "create database IF NOT EXISTS placement;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'localhost' IDENTIFIED BY '$PLACEMENT_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'%' IDENTIFIED BY '$PLACEMENT_DBPASS' ;"
# configure user and endpoint
openstack user create --domain default --password $PLACEMENT_PASS placement
openstack role add --project service --user placement admin
openstack service create --name placement --description "Placement API" placement
openstack endpoint create --region RegionOne placement public http://$CONTROLLER_HOST_NAME:8778
openstack endpoint create --region RegionOne placement internal http://$CONTROLLER_HOST_NAME:8778
openstack endpoint create --region RegionOne placement admin http://$CONTROLLER_HOST_NAME:8778
yum install -y openstack-placement-api
crudini --set /etc/placement/placement.conf placement_database connection mysql+pymysql://placement:$PLACEMENT_DBPASS@$CONTROLLER_HOST_NAME/placement
crudini --set /etc/placement/placement.conf api auth_strategy keystone
crudini --set /etc/placement/placement.conf keystone_authtoken auth_url http://$CONTROLLER_HOST_NAME:5000/v3
crudini --set /etc/placement/placement.conf keystone_authtoken memcached_servers $CONTROLLER_HOST_NAME:11211
crudini --set /etc/placement/placement.conf keystone_authtoken auth_type password
crudini --set /etc/placement/placement.conf keystone_authtoken project_domain_name Default
crudini --set /etc/placement/placement.conf keystone_authtoken user_domain_name Default
crudini --set /etc/placement/placement.conf keystone_authtoken project_name service
crudini --set /etc/placement/placement.conf keystone_authtoken username placement
crudini --set /etc/placement/placement.conf keystone_authtoken password $PLACEMENT_PASS
# populate placement database
su -s /bin/sh -c "placement-manage db sync" placement
systemctl restart httpd
placement-status upgrade check
